package leetcode.每日一题.哈希表;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * @author ：zsy
 * @date ：Created 2023/1/1 6:46 PM
 * @description：
 */
public class 第一个出现两次的字母 {
    @Test
    public void test() {
        System.out.println(new Solution().repeatedCharacter("eesll"));
    }

    class Solution {
        public char repeatedCharacter(String s) {
            int seen = 0;
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                int x = ch - 'a';
                if ((seen & (1 << x)) != 0) {
                    return ch;
                }
                seen |= (1 << x);
            }
            return ' ';
        }
    }

    /*
    class Solution {
        public char repeatedCharacter(String s) {
            char ans = 0;
            Set<Character> set = new HashSet<>();
            for (int i = 0; i < s.length(); i++) {
                if (!set.add(s.charAt(i))) {
                    ans = s.charAt(i);
                    break;
                }
            }
            return ans;
        }
    }
     */
}
